/**
 * 导航栏的下拉
 * 
 * 
 */

$(function () {
  // 我的聚美下拉
  $(".my-jm-box").mouseover(function () {
    $(".my-jm-sel-menu").stop().slideDown(200)
  }).mouseout(function () {
    $(".my-jm-sel-menu").stop().slideUp(200)
  })

  // 更多下拉
  $(".mores").mouseover(function () {
    $(".my-jm-sel-menu1").stop().slideDown(200)
  }).mouseout(function () {
    $(".my-jm-sel-menu1").stop().slideUp(200)
  })

  // 侧边栏 用户部分
  $(".username").mouseover(function () {
    $(".hellow").stop().fadeIn(500)
  }).mouseout(function () {
    $(".hellow").stop().fadeOut(500)
  })


  // 导航栏 美妆商城
  $(".nav-makeup").mouseover(function () {
    $(".nav-makeup-menu").stop().slideDown(200)
  }).mouseout(function () {
    $(".nav-makeup-menu").stop().slideUp(200)
  })


  //去购物车结算
  $(".shop").mouseover(function () {
    $(".box").stop().slideDown(200)
  }).mouseout(function () {
    $(".box").stop().slideUp(200)
  })


  //  侧边栏的滚动事件
  $(document).scroll(function () {
    if ($(document).scrollTop() >= 1500) {
      $(".slide-nav").stop().show(200)
    }
    if ($(document).scrollTop() >= 15100) {
      $(".slide-nav").stop().hide()
    }
    if ($(document).scrollTop() < 1500) {
      $(".slide-nav").stop().hide()
    }
  })


  // top部分
  $(document).scroll(function () {
    console.log($(document).scrollTop());
    if ($(document).scrollTop() > 400) {
      $(".top").css("display", "block")
    }
    if ($(document).scrollTop() < 400) {
      $(".top").css("display", "none")
    }
  })

  // 点击top按钮 让他返回顶部
  $(".top").click(function () {
    $(document).scrollTop = 0 + 'px'
  })



  //  点击购物车让他显示
  $(".shop-car").click(function (e) {
    $(".shop-car").unbind();
    $(".shop-car-box").animate({
      right: "40px",
    }, 100).show()
    e.stopPropagation()
  })
// 解绑事件
  document.querySelector(".shop-car").onclick = null; 
  // 购物车的关闭按钮

  $(".shop-car-close").click(function () {
    document.querySelector(".shop-car-box").style.display = "none";
    setTimeout(function (){
      $(".shop-car").click(function (e) {
        $(".shop-car").unbind();
        $(".shop-car-box").animate({
          right: "40px",
         
        }, 100).show()
        // 阻止冒泡
        e.stopPropagation()
      })
    },10)
  })

})
// tab栏切换
window.onload = function () {
  var tabJob = document.querySelectorAll(".tab-top li");
  var selection = document.querySelectorAll(".selection div");
  console.log(selection)
  for (var i = 0; i < tabJob.length; i++) {
    tabJob[i].setAttribute("index", i);
    tabJob[i].onclick = function () {
      for (j = 0; j < tabJob.length; j++) {
        tabJob[j].removeAttribute("class");
        selection[j].style.display = "none";
      }
      this.className = "current";
      selection[this.getAttribute("index")].style.display = "block";
      return false;
    }
  }

  // 秒杀

  function ShowCountDown(year, month, day, divname) {
    var now = new Date();
    var endDate = new Date(year, month - 1, day);
    var leftTime = endDate.getTime() - now.getTime();
    var dd = parseInt(leftTime / 1000 / 60 / 60 / 24, 10); //计算剩余的天数
    var hh = parseInt(leftTime / 1000 / 60 / 60 % 24, 10); //计算剩余的小时数
    var mm = parseInt(leftTime / 1000 / 60 % 60, 10); //计算剩余的分钟数
    var ss = parseInt(leftTime / 1000 % 60, 10); //计算剩余的秒数
    dd = checkTime(dd);
    hh = checkTime(hh);
    mm = checkTime(mm);
    ss = checkTime(ss); //小于10的话加0
    var cc = document.getElementsByClassName(divname);
    for (var i = 0; i < cc.length; i++) {
      cc[i].innerHTML = dd + "天" + hh + "小时" + mm + "分" + ss + "秒";
    }

  }

  function checkTime(i) {
    if (i < 10) {
      i = "0" + i;
    }
    return i;
  }
  window.setInterval(function () {
    ShowCountDown(2019, 01, 19, 'countdown');
  }, 0);

  // 秒杀

  function ShowCountDown(year, month, day, divname) {
    var now = new Date();
    var endDate = new Date(year, month - 1, day);
    var leftTime = endDate.getTime() - now.getTime();
    var dd = parseInt(leftTime / 1000 / 60 / 60 / 24, 10); //计算剩余的天数
    var hh = parseInt(leftTime / 1000 / 60 / 60 % 24, 10); //计算剩余的小时数
    var mm = parseInt(leftTime / 1000 / 60 % 60, 10); //计算剩余的分钟数
    var ss = parseInt(leftTime / 1000 % 60, 10); //计算剩余的秒数
    dd = checkTime(dd);
    hh = checkTime(hh);
    mm = checkTime(mm);
    ss = checkTime(ss); //小于10的话加0
    var cc = document.getElementsByClassName(divname);
    for (var i = 0; i < cc.length; i++) {
      cc[i].innerHTML = dd + "&nbsp;" + ":" + hh + "&nbsp;" + ":" + mm + "&nbsp;" + ":" + ss;
    }

  }









  //  所有商品的效果
  var todaySeeone = document.querySelectorAll(".today-see-one");
  var newTry = document.querySelectorAll(".new-try");
  var goodsCar = document.querySelectorAll(".goods-one-car");
  for (let i = 0; i < todaySeeone.length; i++) {
    todaySeeone[i].onmouseover = function () {
      newTry[i].classList.add("newtry");
      goodsCar[i].classList.add("goodscar");
    }
    todaySeeone[i].onmouseout = function () {
      newTry[i].classList.remove("newtry");
      goodsCar[i].classList.remove("goodscar");
    }
  }
  //  侧边栏点击效果
  var aa = document.querySelectorAll('#p li')
  for (var i = 0; i < aa.length; i++) {
    aa[i].onclick = function () {
      for (var j = 0; j < aa.length; j++) {
        aa[j].className = ('g')
      }
      this.classList.add('c')
    }
  }
}